{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "Varying the Classification Threshold in Logistic Regression"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([ 0.12889691,  0.16003644,  0.18178279,  0.26026536,  0.19607966,\n",
       "        0.02338669,  0.08582239,  0.30904432,  0.15262031,  0.57532607,\n",
       "        0.19472344,  0.5450249 ,  0.23953703,  0.21645245,  0.73382002,\n",
       "        0.07114854,  0.51769085,  0.2356799 ,  0.27156478,  0.02816506,\n",
       "        0.61623785,  0.62138952,  0.3009406 ,  0.36140993,  0.73721107,\n",
       "        0.31120458,  0.30127869,  0.0954719 ,  0.17749031,  0.79241579,\n",
       "        0.75739679,  0.61102916,  0.18528432,  0.37891817,  0.67945718,\n",
       "        0.13008356,  0.17348681,  0.73142099,  0.33608869,  0.40166906,\n",
       "        0.32009276,  0.14870895,  0.19908409,  0.1071584 ,  0.13930614,\n",
       "        0.26917935,  0.29865454,  0.47265401,  0.12057594,  0.17689581,\n",
       "        0.39158457,  0.60246347,  0.27264813,  0.29989028,  0.19662222,\n",
       "        0.11252416,  0.63628396,  0.10735606,  0.22441409,  0.21347092,\n",
       "        0.57073661,  0.21725055,  0.38204364,  0.06794924,  0.13091798,\n",
       "        0.32752847,  0.35339273,  0.67631321,  0.24438181,  0.57598973,\n",
       "        0.63218632,  0.22776865,  0.25813759,  0.59311201,  0.23978648,\n",
       "        0.73031108,  0.71814552,  0.18505853,  0.44579114,  0.11307711,\n",
       "        0.49075484,  0.69413014,  0.0575423 ,  0.07387488,  0.17027144,\n",
       "        0.4896686 ,  0.51841303,  0.1887861 ,  0.88827136,  0.18168914,\n",
       "        0.1605759 ,  0.08029223,  0.37909566,  0.08458837,  0.25057114,\n",
       "        0.67392141,  0.56158002,  0.59018492,  0.24014737,  0.49181233,\n",
       "        0.13225607,  0.13230957,  0.15568094,  0.27933452,  0.07101258,\n",
       "        0.20947029,  0.07319884,  0.49539054,  0.09691952,  0.38752722,\n",
       "        0.37098581,  0.09494564,  0.46499951,  0.59226021,  0.60843181,\n",
       "        0.84082755,  0.15557607,  0.14163207,  0.3323192 ,  0.13222765,\n",
       "        0.58393935,  0.31962391,  0.82635311,  0.47202601,  0.20588654,\n",
       "        0.16928329,  0.34251   ,  0.53794998,  0.61125529,  0.39289844,\n",
       "        0.37780577,  0.05187275,  0.7306589 ,  0.04983368,  0.23783936,\n",
       "        0.51420024,  0.07077818,  0.27865773,  0.49915744,  0.60511649,\n",
       "        0.35433223,  0.58235164,  0.29773463,  0.31839482,  0.31260391,\n",
       "        0.14691133,  0.15706368,  0.39785794,  0.08176526,  0.19276599,\n",
       "        0.11699399,  0.72069032,  0.07626702,  0.41800724])"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import pandas as pd\n",
    "\n",
    "data_web_address = \"https://archive.ics.uci.edu/ml/machine-learning-databases/pima-indians-diabetes/pima-indians-diabetes.data\"\n",
    "column_names = ['pregnancy_x', \n",
    "                'plasma_con', \n",
    "                'blood_pressure', \n",
    "                'skin_mm', \n",
    "                'insulin', \n",
    "                'bmi', \n",
    "                'pedigree_func', \n",
    "                'age', \n",
    "                'target']\n",
    "\n",
    "feature_names = column_names[:-1]\n",
    "all_data = pd.read_csv(data_web_address , names=column_names)\n",
    "all_data.head()\n",
    "\n",
    "import numpy as np\n",
    "import pandas as pd\n",
    "\n",
    "X = all_data[feature_names]\n",
    "y = all_data['target']\n",
    "\n",
    "\n",
    "from sklearn.model_selection import train_test_split\n",
    "X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=7,stratify=y)\n",
    "\n",
    "from sklearn.linear_model import LogisticRegression\n",
    "lr = LogisticRegression()\n",
    "lr.fit(X_train,y_train)\n",
    "\n",
    "y_pred = lr.predict(X_test)\n",
    "y_pred_proba = lr.predict_proba(X_test)\n",
    "y_pred_proba[:,1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "from sklearn.metrics import roc_curve\n",
    "\n",
    "fpr, tpr, ths = roc_curve(y_test, y_pred_proba[:,1])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[<matplotlib.lines.Line2D at 0xd2a8358>]"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXkAAAEACAYAAABWLgY0AAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAG7BJREFUeJzt3XmUlNWZx/Hv02yiIIoIIghEEJDVIAKOKCUKNFHCYlTA\nECJR0IhLook640JEx2WOHhA0ihtRTHAiGUFHhkVtRQVFQRYFBBdkURxliTLBsNz54xZSNr1Ud1fV\nfavq9zmnj7Vc3v6lmjw8fd/73tecc4iISG4qCB1ARETSR0VeRCSHqciLiOQwFXkRkRymIi8iksNU\n5EVEcli5Rd7MHjOzLWa2vIwx95vZWjN7z8xOSm1EERGprGQ6+SeAfqW9aWb9gZbOuROAMcBDKcom\nIiJVVG6Rd869DmwrY8hA4Mn42LeAembWKDXxRESkKlIxJ98E2JDwfFP8NRERCUwnXkVEclj1FBxj\nE3BcwvOm8dcOYmbaKEdEpBKcc1aZP5dsJ2/xr5LMAn4BYGY9gO3OuS2lHcg5F6mvW2+9tcrHePpp\nx/nnRy9XFD8rZVKmqOeKYqaqSGYJ5Z+BN4HWZvaZmV1sZmPMbHS8aL8IfGJm64CHgV9XKVEWatcO\nVq0KnUJE5GDlTtc454YnMWZsauJkpzZtYO1a6NnTP//5z+Gyy8JmEhGB1MzJZ7VYLFblY9SuDYsX\nw44dsGgRzJpV9SKfilyppkzJUabkRTFXFDNVhVV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/BOk/8ZrMZ9Uo4XE34NMIZGoLzIuPPRTfDbYL/bPDnxD+Gqgdhb9PwAPA\nrft/jvhplPoRyFUPqBF/fCkwtdzjpilsIbAmXqBuiL82BhidMGZy/H/QMqBLBn6wZWZK+EFuB7YC\nnwF1Amd6JP4Xfwn+17K3I/A5/R5YGc/0BnBqujMl+3cqYezjpLnIJ/lZXRH/rJYCbwLdQ2eKP78O\nv8JmOXBlRDKNBP6cib9LSf7sGgNz4p/RcmBYRHL1iL+/Cr/IoF55x9TFUCIiOUy7UIqI5DAVeRGR\nHKYiLyKSw1TkRURymIq8iEgOU5EXEclhKvIiIjlMRV5EJIf9P5CvR90KTOIRAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0xc14d080>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "import matplotlib.pyplot as plt\n",
    "%matplotlib inline\n",
    "\n",
    "plt.plot(ths,tpr)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[54,  0],\n",
       "       [81, 19]], dtype=int64)"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from sklearn.preprocessing import binarize\n",
    "from sklearn.metrics import confusion_matrix\n",
    "y_pred_th= binarize(y_pred_proba, threshold=0.1)\n",
    "confusion_matrix(y_test, y_pred_th[:,1],labels=[1,0])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[54,  0],\n",
       "       [67, 33]], dtype=int64)"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "y_pred_th = binarize(y_pred_proba, threshold=0.146)\n",
    "confusion_matrix(y_test, y_pred_th[:,1],labels=[1,0])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[<matplotlib.lines.Line2D at 0xd4b22b0>]"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXkAAAEACAYAAABWLgY0AAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAADq9JREFUeJzt3V+IZGeZx/HvL85mYSWGjIGAExN2oyEoRhGdnYvAlols\nOt6MeLNJIGJAGNiNeGeSC5m+EFzvxA0qA4PihYxgFnbWVYxICsluoiPkj64zzkSXMTORSJxWUAiM\nw7MXVZkpy+qu6ur60/329wMFdarePv3MS/evzzzn1HtSVUiS2nTVsguQJM2PIS9JDTPkJalhhrwk\nNcyQl6SGGfKS1LCxIZ/kaJJXkrywwZgvJDmT5Lkk75ltiZKkaU1yJP8V4O713kxyD3BLVb0dOAR8\neUa1SZK2aGzIV9VTwNoGQw4CX+uP/SFwbZIbZlOeJGkrZtGT3we8NLB9vv+aJGnJPPEqSQ3bM4N9\nnAfeOrB9Y/+1v5DEhXIkaQpVlWm+btIj+fQfoxwHPgqQ5ADwu6p6Zb0dVZWPKg4fPrz0GrbLw7lY\n3FzA8v+N22UudtJjK8YeySf5OtAB3pzkV8Bh4OpeXteRqvp2kg8leRH4I/DgliqSJM3M2JCvqvsn\nGPPQbMqRJM2SJ16XpNPpLLuEbcO5uGKaudi7F5LJHtddN/ua58Wfi9nIVvs9m/pmSS3y+0m7QQL+\nWrUtCTXnE6+SpB3IkJekhhny0pJtpqe+0/vsWjx78tKS2VPXOPbkJUkjGfKS1LBZrF0jNWfvXljb\naIHtGbKnrnmyJy+NYJ9c24k9eUnSSIa8JDXMnryaMOseun1ytcKevJpgD10tsycvSRrJkJekhhny\n2rEG13yxhy6NZk9eO5Z9eO0W9uQlSSMZ8pLUMENeO8bwuuv24aXx7Mlrx7AHr93Knr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SGGfKS1DBDXpIaZshLUsMMeUlqmCEv\nSQ0z5CWpYYa8JDXs/wH9Y/d11KrMdQAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0xd1c0240>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "#Plotting an ROC Curve without Context\n",
    "\n",
    "\n",
    "from sklearn.metrics import roc_curve\n",
    "\n",
    "fpr, tpr, ths = roc_curve(y_test, y_pred_proba[:,1])\n",
    "plt.plot(fpr,tpr)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.82518518518518524"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from sklearn.metrics import auc\n",
    "\n",
    "auc(fpr,tpr)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.11"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
